package Improvement;

import java.util.ArrayList;

import XmlLoader.FGObjectStructure;
import XmlLoader.FGObjectTrajectoryStructure;
import XmlLoader.Position;
import XmlLoader.Size;

public class GridTraj {
	protected ArrayList<Cube> listCube = new ArrayList<Cube>();
	
	public GridTraj() {}
	
	public GridTraj(FGObjectTrajectoryStructure traj, int size, Size bbox) {
		int indexP = 0;
		while(indexP < traj.GET002_nNumberOfPoint()) {
			FGObjectStructure obj = traj.GET003_elementIn_list_fGObject(indexP);
			Position p = obj.GET001_centerReal();
			Cube c = new Cube((p.x / size) * size, (p.y / size) * size, size, size);
			if(listCube.size() == 0 || (listCube.size() > 0 && !listCube.get(listCube.size() - 1).isEquall(c))) {
				listCube.add(c);
			}
			indexP = indexP + 1;
		}
	}
	
	public void ACT001_show() {
		int index = 0;
		while(index < this.listCube.size()) {
			Cube c = this.listCube.get(index);
			System.out.println(c.pos.x + " " + c.pos.y + " " + c.length + " " + c.width);
			index = index + 1;
		}
	}
	
	public void ACT002_insertCube(Position pos, int size) {
		this.listCube.add(new Cube(pos.x, pos.y, size, size));
	}
	
	public Cube GET001_element(int index) {
		return this.listCube.get(index);
	}
	
	public int GET002_length() {
		return this.listCube.size();
	}
}
